package com.modelscope.ai.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.modelscope.ai.domain.dto.DikeQueryCriteria;
import com.modelscope.ai.domain.entity.Dike;
import com.modelscope.ai.domain.entity.R;
import com.modelscope.ai.domain.entity.SubscribeArticle;
import com.modelscope.ai.domain.entity.Visit;
import com.modelscope.ai.domain.vo.VisitVo;
import com.modelscope.ai.service.DikeService;
import com.modelscope.ai.service.SubscribeArticleService;
import com.modelscope.ai.service.VisitService;
import com.modelscope.ai.utils.RequestHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

// @Tag	用在controller类上，描述此controller的信息
//@Operation	用在controller的方法里，描述此api的信息
//@Parameter	用在controller方法里的参数上，描述参数信息
//@Parameters	用在controller方法里的参数上
//@Schema	用于Entity，以及Entity的属性上
//@ApiResponse	用在controller方法的返回值上
//@ApiResponses	用在controller方法的返回值上
//@Hidden	用在各种地方，用于隐藏其api
//————————————————
@RequiredArgsConstructor
@Slf4j
@Validated
@RestController
@RequestMapping("/visit")
@Tag(name = "visit", description = "访问记录")
public class VisitController {

    private final VisitService visitService;
    private final SubscribeArticleService subscribeArticleService;

    @GetMapping("/addVisited")
    public R<String> addVisited(Long articleItemId) {
        Long uid = RequestHolder.get().getUid();
        visitService.addVisited(uid, articleItemId);
        return R.ok("新增成功");
    }

    @GetMapping("/addSubscribe")
    public R<String> add(Long articleId) {
        Long uid = RequestHolder.get().getUid();
        SubscribeArticle subscribeArticle = new SubscribeArticle();
        subscribeArticle.setArticleId(articleId);
        subscribeArticle.setUid(uid);
        subscribeArticleService.addSubscribeArticle(subscribeArticle);
        return R.ok("新增成功");
    }

    @GetMapping("/list")
    public R<List<VisitVo>> queryAll() {
        Long uid = RequestHolder.get().getUid();
        return R.ok(visitService.getVisited(uid));
    }

    @PutMapping("/delete")
    public R<String> deleteSubScribe(@RequestBody List<Long> ids) {
        subscribeArticleService.deleteSubscribeArticle(ids);
        return R.ok("删除订阅成功");
    }

}
